package com.nbgroup.controller;

import com.nbgroup.pojo.RoleMenu;
import com.nbgroup.pojo.common.Result;
import com.nbgroup.pojo.dto.MenuDto;
import com.nbgroup.pojo.vo.MenuTreeselectVO;
import com.nbgroup.pojo.vo.MenuVo;
import com.nbgroup.pojo.vo.RoleMenuResult;
import com.nbgroup.service.MenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "菜单接口")
@RequestMapping("/system/menu")
public class MenuController {
    @Autowired
    private MenuService menuService;

    @GetMapping("/list")
    @ApiOperation("查询全部")
    public Result allList(MenuVo menuvo) {
        List<MenuVo> list = menuService.allList(menuvo);
        return Result.success(list);
    }

    @PostMapping()
    @ApiOperation("新增菜单")
    public Result addMenu(@RequestBody MenuVo menuVo) {
        menuService.addMenu(menuVo);
        return Result.success();
    }

    @GetMapping("/{menuId}")
    @ApiOperation("查询会显")
    public Result selectById(@PathVariable Integer menuId) {
        MenuVo menuVo = menuService.selectById(menuId);
        return Result.success(menuVo);
    }

    @PutMapping()
    @ApiOperation("修改菜单")
    public Result update(@RequestBody MenuDto menuDto) {
        menuService.update(menuDto);
        return Result.success();
    }

    @DeleteMapping("/{menuId}")
    @ApiOperation("删除菜单")
    public Result delete(@PathVariable Integer menuId) {
        menuService.delete(menuId);
        return Result.success();
    }
    @GetMapping("/treeselect")
    @ApiOperation("查询全部菜单权限")
    public Result queryAllMenuS(){
    List<MenuTreeselectVO> menuVos =menuService.queryAllMenuS();
    return Result.success(menuVos);
    }
    @GetMapping("/roleMenuTreeselect/{roleId}")
    @ApiOperation("根据角色id查询菜单权限")
    public RoleMenuResult queryMenuByRole(@PathVariable Long roleId){
        RoleMenuResult roleMenuResult= menuService.queryMenuByRole(roleId);
    return roleMenuResult;
    }
}
